package com.hxd.otc.module.convenience.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.convenience.bean.ConvenienveHistoryBean;
import com.hxd.otc.module.convenience.bean.NorGoodsBean;
import com.hxd.otc.module.convenience.bean.WaterCoalBillBean;
import com.hxd.otc.module.convenience.contract.HydropwerListContract;
import com.hxd.otc.module.convenience.model.ConvenienceModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;

import java.util.ArrayList;
import java.util.List;

/**
 * 包  名 :  com.example.administrator.blocksbankclient.mvp.order
 * 类  名 :  OrderPresenter
 * 作  者 :  zjl
 * 时  间 :  2018/6/4 17:02
 * 描  述 :  ${TODO}所有订单页面P
 */
public class HydropowerListPresenter extends BasePresenter<HydropwerListContract.View> implements HydropwerListContract.Presenter {

    ConvenienceModel model;
    List<ConvenienveHistoryBean> list;

    public HydropowerListPresenter(HydropwerListContract.View view) {
        super(view);
        model = ConvenienceModel.getInstance();
    }

    public List<ConvenienveHistoryBean> getList() {
        return list;
    }

    @Override
    public void onLoadLabel(String businessType) {
        model.getHydropowerHistoryList(businessType, new BaseObserver<ArrayList<ConvenienveHistoryBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ArrayList<ConvenienveHistoryBean> beans) {
                list = beans;
                doSetLabelAdapter(list);
                doLabelShowNoMore();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
                doLabelShowNoMore();
            }
        }, mView.<BaseBean<ArrayList<ConvenienveHistoryBean>>>bindAutoDispose());
    }

    @Override
    public void onLoadHydropwer(String id) {
        model.getGoodsList(id, new BaseObserver<ArrayList<NorGoodsBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ArrayList<NorGoodsBean> beans) {
                doSetHydropwerAdapter(beans);
                doHydropwerShowNoMore();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
                doHydropwerShowNoMore();
            }
        }, mView.<BaseBean<ArrayList<NorGoodsBean>>>bindAutoDispose());
    }

    @Override
    public void onDelete(String id) {

        model.deleteHistory(id, new BaseObserver() {
            @Override
            public void onNext(@NonNull String msg, @NonNull Object o) {
                mView.onDeleteSucced();
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {

                mView.showToast(errMessage);
            }

        }, mView.<BaseBean>bindAutoDispose());
    }

    @Override
    public void getArrearage(String... parameters) {
        model.getArrearage(parameters[0], parameters[1], new BaseObserver<ArrayList<WaterCoalBillBean>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull ArrayList<WaterCoalBillBean> billBeanArrayList) {
                mView.setArrearage(billBeanArrayList.get(0));
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {
                mView.showToast(errMessage);
            }
        }, mView.<BaseBean<ArrayList<WaterCoalBillBean>>>bindAutoDispose());
    }

    @Override
    public void doHydropwerShowNoMore() {

        mView.onHydropwerShowNoMore();
    }

    @Override
    public void doSetHydropwerAdapter(List<NorGoodsBean> list) {
        mView.onSetHydropwerAdapter(list);
    }

    @Override
    public void doLabelShowNoMore() {
        mView.onLabelShowNoMore();
    }

    @Override
    public void doSetLabelAdapter(List<ConvenienveHistoryBean> list) {
        mView.onSetLabelAdapter(list);
    }


}
